package com.hspedu.transformation;

import java.io.*;

/**
 * @Author Stringzhua
 * @Date 2024/3/17 13:21
 * description:使用InputStreamReader 转换流解决中文乱码问题
 * 将字节流FileInputStream 转成字符流
 */
public class InputStreamReader_ {
    public static void main(String[] args) throws IOException {
        String filePath = "e:\\qiyeke\\filecontroller\\a.txt";
        //解读
        //1.把FileInputStream 转为 InputStreamReader
        //2.指定编码gbk
//        InputStreamReader isr = new InputStreamReader(new FileInputStream(filePath), "gbk");
        //3.把 InputStreamReader 传入 BufferedReader
//        BufferedReader br = new BufferedReader(isr);
        //将2、3合在一块
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filePath),"gbk"));
        //4.读取文件内容
        String s = br.readLine();
        System.out.println("读取的内容为=" + s);
        //5.关闭外层流
        br.close();
//        PrintStream
//        PrintWriter
    }
}
